import Mock from "mockjs";

const TemplateMatchOk = {
  code: 0,
  data: {
    match: true
  }
}

const TemplateMatchFail = {
  code: 0,
  data: {
    match: true
  }
}

const ValidateRepeat = {
  code: 0,
  data: {
    flag: 1
  }
}

const ValidateAuditing = {
  code: 0,
  data: {
    flag: 2
  }
}

const ValidateOk = {
  code: 0,
  data: {
    validate: true
  }
}

const ValidateError = {
  code: 11121,
  data: {
    // validate: true
  },
  message: '报价验证异常'
}
const VALIDATE_RESULTS = [ValidateError, ValidateOk, ValidateAuditing, ValidateRepeat]

function createValidateResponse () {
  const index = Math.round(Math.random() * 3)
  return VALIDATE_RESULTS[index]
}

function createMatchResponse () {
  return Math.round(Math.random()) ? TemplateMatchFail : TemplateMatchOk
}

Mock.mock(RegExp("/quotation/template/match"), "post", () => {
  const response = createMatchResponse();
  console.log("Use mock quotation match data:", response)
  return response
})

Mock.mock(RegExp("/quotation/validate/\\d+"), "get", () => {
  const response = createValidateResponse()
  console.log("Use mock quotation validate data:", response)
  return response
})
